﻿using Microsoft.TeamFoundation.VersionControl.Client;

namespace TFSTools.TFSLibrary.VersionControl
{
    public sealed class TFSVersionControl : TFSServerEntity
    {
        private VersionControlServer serverVersionControlServer;

        internal TFSVersionControl(ITFSConnection connection)
            : base(connection)
        {
            this.serverVersionControlServer = this.SelectedTeamProjectCollection.GetService<VersionControlServer>();
        }

        internal VersionControlServer Service { get { return this.serverVersionControlServer; } }

        public TFSItemSecurityCollection GetAllPermissionsForSelectedProject()
        {
            string[] items = { "$/" + this.Connection.SelectedProject.Name };
            return TFSItemSecurityCollection.Create(this.Connection, this.serverVersionControlServer.GetPermissions(items, RecursionType.Full));
        }

        public TFSPendingSetCollection GetAllPendingSetsForSelectedProject()
        {
            string[] items = { "$/" + this.Connection.SelectedProject.Name };
            return TFSPendingSetCollection.Create(this.Connection, this.serverVersionControlServer.GetPendingSets(items, RecursionType.Full));
        }

        public override string ToString() { return this.serverVersionControlServer.ToString(); }
    }
}
